package com.haopt.elasticjob.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.haopt.elasticjob.annotation.ElasticSimpleJob;
import com.haopt.elasticjob.config.MyJobShardingStrategy;
import com.haopt.elasticjob.config.MyListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author haopt
 * @version 1.0
 * @ClassName JobTest
 * @Description TODO
 * @date 2021/5/13 22:55
 */
@Slf4j
@Component
@ElasticSimpleJob(jobName = "mySimpleJob",
        corn = "0/5 * * * * ?",
        shardingTotalCount = 10,
        overwrite = true,
        monitorExecution = true,
        failover = true,
        jobShardingStrategyClass = MyJobShardingStrategy.class,
        listeners = MyListener.class
)
public class SimpleJobTest implements SimpleJob {
    @Override
    public void execute(ShardingContext shardingContext) {
        int shardingTotalCount = shardingContext.getShardingTotalCount();
        int shardingItem = shardingContext.getShardingItem();
        System.out.println("总分片数为：" + shardingTotalCount + "--当前分片数为：" + shardingItem);
    }
}
